﻿Imports Oracle.DataAccess.Client
Public Class fListaCentroSumi
    Private lCentroSumi As String
    Public ReadOnly Property mIdCentroSumi()
        Get
            Return lCentroSumi
        End Get
    End Property

    Private Sub btnConsulta_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsulta.Click
        Dim qWhere As String = "WHERE "
        Dim qSelect As String = "SELECT * FROM COM_CENTROSUMI "
        Dim CuentaW As Int16 = 0
        If txtCentroSumi.Text.Trim.Length > 0 Then
            CuentaW += 1
            qWhere &= "DESCRIPCION LIKE '%" & Me.txtCentroSumi.Text & "%'"
        End If
        If CuentaW = 0 Then _
            qWhere = ""
        Dim Conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
        Dim cmd As OracleCommand = Conn.CreateCommand
        cmd.CommandText = qSelect + qWhere
        Try
            Conn.Open()
            DsCompras.COM_CENTROSUMI.Rows.Clear()
            DsCompras.COM_CENTROSUMI.Load(cmd.ExecuteReader)
            Conn.Close()
            COM_CENTROSUMIDataGridView.Focus()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub COM_CENTROSUMIDataGridView_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles COM_CENTROSUMIDataGridView.CellMouseDoubleClick
        If e.RowIndex >= 0 Then
            lCentroSumi = Me.COM_CENTROSUMIDataGridView.Rows(e.RowIndex).Cells("IDCENTROSUMI").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub AsignaDatos(ByVal Fila As Integer)
        If Fila >= 0 Then
            lCentroSumi = COM_CENTROSUMIDataGridView.Rows(Fila).Cells("IDCENTROSUMI").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub


    Private Sub COM_CENTROSUMIDataGridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles COM_CENTROSUMIDataGridView.KeyDown
        If e.KeyData = Keys.Enter Then
            AsignaDatos(COM_CENTROSUMIDataGridView.CurrentRow.Index)
        End If
    End Sub
End Class